package cn.edu.hzw.comic.mvp.view

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import cn.edu.hzw.comic.R
import cn.edu.hzw.comic.mvp.model.snackbar
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.fragment_page.*


class PageFragment(val link:String) : Fragment() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_page, container, false)
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        progressBar.visibility = View.VISIBLE
    }

    override fun onResume() {
        super.onResume()
        Picasso.with(context).load(link).placeholder(R.color.white).into(imageView,object :Callback{
            override fun onSuccess() {
                progressBar.visibility = View.GONE
            }

            override fun onError() {
                imageView.snackbar(R.string.network_error)
            }
        })
    }

}